// pages/admin4TeacherPage/index4Teacher/index4Teacher.js
var app = getApp();
import util from '../../../utils/util.js';
const FN = require('../../../utils/public');
import commonAPI from '../../../api/api'
var page = 1;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    HomeworkTypeStatus: false,
    page: 1,
    appHeight: '',
    priTmplIdArr:[],
    hwList: [],
    userInfo: {},
    teacherInfo: {}
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    var that = this;
    this.initData(1);
    this.getSubscribeMsg();
  },

  // 学员回复提醒
  subscribeMessage: function (e) {
    var that = this;
    wx.requestSubscribeMessage({
      tmplIds: that.data.priTmplIdArr, // 学员回复提醒
      success(res) {}
    })
    that.repeatDetail(e);
  },

  // 跟读情况
  repeatDetail: function (e) {
    var hwid = e.currentTarget.dataset.homeworkid;
    wx.navigateTo({
      url: '../homeworkDetail/homeworkDetail?hwid=' + hwid
    })
  },

  // 初始话数据
  initData: function (p) {
    var that = this;
    commonAPI.getTeaAllHomework({  pageNum: p,
      pageSize: 15}).then(res => {
      if (res.code == '200') {
        if (res.data.list.length == 0) {
          FN.Toast('没有更多数据了')
        } else {
          var resArr = that.data.hwList;
          resArr.push.apply(resArr, res.data.list); //上拉加载
          that.setData({
            hwList: resArr
          })
        }
      }
    })
  },

// 获取订阅消息
getSubscribeMsg: function () {
  var that = this;
  commonAPI.getSubscribeMsg({ pageUrl: util.getCurrentPageUrl() }).then(res => {
    if (res.code == '200' && res.data.length > 0) {
      var arr = res.data[0].priTmplIdArr.split(",")
      that.setData({
        priTmplIdArr: arr
      })
    }
  })
},

  // 上拉加载跟多数据
  reachBottom() {
    page++;
    this.initData(page);
  },

  // 选择作业类型
  selectHWType() {
    this.setData({
      HomeworkTypeStatus: true
    })
  },

  // 关闭选择页面
  closeSelectHWtype() {
    this.setData({
      HomeworkTypeStatus: false
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {
     
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {
    var that = this;
    page = 1;
    that.initData(1);
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {
    page++;
    this.initData(page);
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})
